package example.util;

import okhttp3.*;

import java.io.IOException;

public class http {

    public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");

    static final OkHttpClient client = new OkHttpClient();

    static public String post() throws IOException {

        RequestBody requestBody = RequestBody.create("", JSON);

        //创建一个请求对象
        Request request = new Request.Builder()
                .url("url")
                .addHeader("key", "value")
                .post(requestBody)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (response.body() != null) {
                return response.body().string();
            }
        }

        return null;
    }
}
